<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="/favicon.ico">

    <title>修改头像</title>

    <!-- Bootstrap core CSS -->
    <link href="/css/bootstrap.min.css" rel="stylesheet">



    <!-- Custom styles for this template -->
    <link href="navbar-fixed-top.css" rel="stylesheet">

    <style>
        
        #title{
            margin-top: 70px;
        }
        .content{
            width: 50%;
            float: left;
            height:100px;
        }
        .setavatar{
            margin-top: 20px;
            margin-bottom: 30px;
        }

    </style>



</head>

<body>

<!-- Fixed navbar -->
<nav class="navbar navbar-default navbar-fixed-top">
    <div class="container">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">班级说说</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
            <ul class="nav navbar-nav">
                <li ><a href="/">全部说说</a></li>
                <li><a href="#contact">我的说说</a></li>
                
            </ul>
            <ul class="nav navbar-nav navbar-right">
                <li class="active"><a href="/login">设置头像</a></li>
            </ul>
        </div><!--/.nav-collapse -->
    </div>
</nav>

<div class="container">

   <h2 id="title">设置头像</h2>
    <!-- Main component for a primary marketing message or call to action -->


    <div class="content">
        <form id="imgForm" action="/dosetavatar" method="post" enctype="multipart/form-data">
            <input type="file"   name="setavatar" class="setavatar" placeholder="设置头像" onchange="loadImg()">
            <input type="submit" name="submit" class="btn btn-default" value="提交"> </input>
        </form>
    </div>
    <div class="content">
        <img src="" id="icon" style="height: 80px;width: 80px;">
    </div>
        


</div> <!-- /container -->
<script src="js/jquery-1.11.3.min.js"></script>

<script src="js/bootstrap.min.js"></script>
<script>
    function loadImg(){
        //获取文件
        var file = $("#imgForm").find("input")[0].files[0];

        //创建读取文件的对象
        var reader = new FileReader();

        //创建文件读取相关的变量
        var imgFile;

        //为文件读取成功设置事件
        reader.onload=function(e) {
            imgFile = e.target.result;
            console.log(imgFile);
            $("#iocn").attr('src', imgFile);
        };

        //正式读取文件
        reader.readAsDataURL(file);
    }
    loadImg();
</script>
</body>
</html>
